<template>
  <div>
    <van-form @submit="onSubmit">
      <van-cell-group inset>
        <van-field
          v-model="reactiveFrom.username"
          name="username"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="reactiveFrom.password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
          v-model="reactiveFrom.passwordok"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ valdata, message: '请填写密码' }]"
        />
      </van-cell-group>
      <div style="margin: 16px">
        <van-button round block type="primary" native-type="submit" @click="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import { useRouter } from "vue-router";
let reactiveFrom = reactive({
  username: "",
  password: "",
  passwordok: "",
});
let router =new useRouter()
import { showToast } from 'vant';
import {zheceApi} from '@/api/api'
const valdata=(val)=>
{
    if(val!=reactiveFrom.password)
{
 return false
}
return true
}
const submit=()=>
{
    zheceApi(reactiveFrom.username,reactiveFrom.password).then(res=>
        {
            console.log('注册',res)
            if(res.data.code==0)
        {
            showToast({
                message:'注册成功',
                type:'success',
                onClose()
                {
                    router.push('/login')
                }
            })
        }
        else
        {
            showToast({
                message:'重复注册',
                type:'fail'
            })
        }
        }
    )
}
</script>

<style lang="scss" scoped>
</style>